<?php
function html_add_comment($post_id = 0,$type = '') {
   $html = '<div class="add_comment">
               <div class="add_comment_avatar">
                  <img src="/themes/img/avatar_guest.jpg" alt="avatar guest add new comments" />
               </div>
               <div class="add_comment_main">
                  <textarea class="add_comment_content"></textarea>
                  <div class="add_comment_meta">';
         if(isset($_COOKIE['comment_name'])) {
            $html .= '<span>
                        Bình luận với tên 
                        <strong title="'.$_COOKIE['comment_email'].'">'.$_COOKIE['comment_name'].'</strong>
                        (<a class="remove_sc_cmt" href="javascript:"  data-pid="'.$post_id.'" data-type="'.$type.'">thoát</a>)
                     </span>
                     <input type="hidden" name="add_comment_email" class="add_comment_email" value="'.$_COOKIE['comment_email'].'" />
                     <input type="hidden" name="add_comment_name" class="add_comment_name" value="'.$_COOKIE['comment_name'].'" />';
         }else {
            $html .= '<input type="text" name="add_comment_email" class="add_comment_email" placeholder="Nhập email của bạn (*)" />
                      <input type="text" name="add_comment_name" class="add_comment_name" placeholder="Nhập tên của bạn (*)" />';
         }
            $html .= '<button class="add_comment_btn" data-pid="'.$post_id.'" data-type="'.$type.'">Gửi</button>
                  </div>
               </div>
            </div>';
   return $html;
}
function html_list_comment($post_id = 0,$type = '',$count_comment=0) {
   $html = '';
   if($count_comment == 0) {
      $db_count_cmt = new db_count('SELECT count(com_id) as count 
                                    FROM comments 
                                    WHERE com_post_id = '.$post_id.' AND com_type = "'.$type.'"');
      $count_comment = $db_count_cmt->total;
   }
   if($count_comment > 0) {
      $list_comments = db_array('SELECT * FROM comments WHERE com_post_id = '.$post_id.' AND com_type = "'.$type.'" ORDER BY com_id DESC LIMIT 10');
      $html .= '<div class="list_comment">
                  <p class="list_comment_count">Có '.$count_comment.' bình luận</p>';
      foreach($list_comments as $comment) {
         $html .= '<div class="comment_item">
                     <img src="/themes/img/avatar_guest.jpg" alt="avatar guest comment" />
                     <p class="cmt_name"><strong>'.$comment['com_name'].'</strong></p>
                     <p class="cmt_content">'.$comment['com_content'].'</p>
                     <p class="cmt_meta">
                        <span class="cmt_reply" data-id="'.$comment['com_id'].'">Trả lời</span>
                        <span class="cmt_like" data-id="'.$comment['com_id'].'" data-type="comment" data-like="'.$comment['com_like'].'">Thích <i class="icon_like"></i> <span>'.$comment['com_like'].'</span></span>
                        <span class="cmt_date">'.getTodayYesterdayString($comment['com_date']).'</span>
                     </p>
                  </div>';
         $list_reply = db_array('SELECT * FROM comments_reply WHERE rep_comment_id = '.$comment['com_id'].' LIMIT 3');
         foreach($list_reply as $reply) {
            $repqtv = ($reply['rep_admin'] > 0) ? ' <span class="tagqtv">Quản trị viên</span>' : '';
            $html .= '<div class="reply_item">
                        <img src="/themes/img/avatar_guest.jpg" alt="avatar guest comment" />
                        <p class="cmt_name"><strong>'.$reply['rep_name'].'</strong>'.$repqtv.'</p>
                        <p class="cmt_content">'.$reply['rep_content'].'</p>
                        <p class="cmt_meta">
                           <span class="cmt_like" data-id="'.$reply['rep_id'].'" data-type="reply" data-like="'.$reply['rep_like'].'">Thích <i class="icon_like"></i> <span>'.$reply['rep_like'].'</span></span>
                           <span class="cmt_date">'.getTodayYesterdayString($reply['rep_date']).'</span>
                        </p>
                     </div>';
         }
      }
      if($count_comment > 10) {
         $html .= '<div class="more_cmt" data-pid="'.$post_id.'" data-type="'.$type.'" data-page="1">Xem thêm bình luận ▼ <span></span></div>';
      }
      $html .= '</div>';
   }else {
      $html .= '<div class="list_comment">
                  <p class="list_comment_count">Có '.$count_comment.' bình luận</p>
               </div>';
   }
   
   return $html;
}
?>